//
//  ASSettingCell.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 16/2/17.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASSettingCell.h"

@implementation ASSettingCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        CGFloat fontSize = 16;
        CGFloat padding = 17;
        CGFloat bgWidth = [[UIScreen mainScreen] bounds].size.width;
        
        // leftText
        _leftText = [[UILabel alloc] initWithFrame:CGRectZero];
        _leftText.frame = CGRectMake(padding, 1, bgWidth - padding - 100, 50 - 1);
        [_leftText setBackgroundColor:[UIColor clearColor]];
        [_leftText setTextColor:RGB(51, 51, 51)];
        [_leftText setFont:[UIFont systemFontOfSize:fontSize]];
        [self.contentView addSubview:_leftText];
        
        
        // rightImage
        _rightImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        _rightImage.frame = CGRectMake(bgWidth - 30, (50 - 20) / 2, 10.5, 20);
        [_rightImage setImage:[UIImage imageNamed:@"ic_next"]];
        [self.contentView addSubview:_rightImage];
        
        // msgReminder
        _msgReminder = [[UISwitch alloc] initWithFrame:CGRectZero];
        _msgReminder.frame = CGRectMake(bgWidth - 70, 10, 40, 30);
        [_msgReminder addTarget:self action:@selector(onChanged:) forControlEvents:UIControlEventValueChanged];
        [self.contentView addSubview:_msgReminder];
        
        // topLine
        _topLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, bgWidth, 1)];
        [_topLine setBackgroundColor:RGB(221.0, 221.0, 221.0)];
        [self.contentView addSubview:_topLine];
        
        // bottomLine
        _bottomLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, 50 - 1, bgWidth, 1)];
        [_bottomLine setBackgroundColor:RGB(221.0, 221.0, 221.0)];
        [self.contentView addSubview:_bottomLine];
    }
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    return self;
}

- (void)onChanged:(id)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(msgReminderSwitchChanged:leftTitle:)])
    {
        [self.delegate msgReminderSwitchChanged:self.msgReminder.on leftTitle:_leftText.text];
    }
}

- (void)updateCellStatus:(NSString *)leftText
{
    _leftText.text = leftText;
    
    if ([leftText isEqualToString:@"修改密码"])
    {
        _rightImage.hidden = NO;
        _msgReminder.hidden = YES;
        
        _topLine.hidden = NO;
        _bottomLine.hidden = NO;
    }
    else
    {
        _rightImage.hidden = YES;
        _msgReminder.hidden = NO;
        
        _topLine.hidden = YES;
        _bottomLine.hidden = NO;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
